from pages.base_page import BasePage
from selenium.webdriver.common.by import By


class BusinessHomePage(BasePage):
    url = '/crm/index.php?m=business'
    #定位器
    add_new_business_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div:nth-child(1) > div > a')
    business_name_locator = (By.ID,'name')
    estimate_price_locator = (By.ID,'estimate_price')
    customer_name_locator = (By.ID,'customer_name')
    fields_locator = (By.ID,'fields')
    searchs_locator = (By.ID,'searchs')
    searchs_btn_locator = (By.CSS_SELECTOR,'#dialog-message > div > ul > li:nth-child(4) > button')
    first_customer_name_locator = (By.XPATH,'/html/body/div[10]/div[2]/table/tbody[2]/tr[1]/td[1]/input[1]')
    sure_button = (By.CSS_SELECTOR,'body > div:nth-child(17) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1) > span')
    save_button = (By.CSS_SELECTOR,'#form1 > table > tfoot > tr > td > input:nth-child(1)')
    save_success_locator = (By.CSS_SELECTOR,'body > div.container > div.alert.alert-success')
    save_error_locator = (By.CSS_SELECTOR,'body > div > form > fieldset > div.alert.alert-error')
    first_business_view_locator = (By.XPATH,'/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[1]/td[12]/a[1]')
    first_business_edit_locator = (By.XPATH,'/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[1]/td[12]/a[3]')
    #点击新建商机
    def click_new_business(self):
        self.driver.find_element(*self.add_new_business_locator).click()

    def input_business_name(self,business_name):
        self.driver.find_element(*self.business_name_locator).send_keys(business_name)
    def input_estimate_price(self,estimate_price):
        self.driver.find_element(*self.estimate_price_locator).send_keys(estimate_price)

    def click_customer_name(self):
        self.driver.find_element(*self.customer_name_locator).click()
    def click_fields(self):
        return self.driver.find_element(*self.fields_locator)

    def click_searchs(self,customer_name):
        self.driver.find_element(*self.searchs_locator).send_keys(customer_name)

    def click_searchs_button(self):
        self.driver.find_element(*self.searchs_btn_locator).click()

    def check_first_customer_name(self):
        self.driver.find_element(*self.first_customer_name_locator).click()

    def click_sure_button(self):
        self.driver.find_element(*self.sure_button).click()

    def click_save_button(self):
        self.driver.find_element(*self.save_button).click()
    def save_success(self):
        return self.driver.find_element(*self.save_success_locator).text


    def save_error(self):
        return self.driver.find_element(*self.save_error_locator).text

    def enter_business_view_page(self):
        self.driver.find_element(*self.first_business_view_locator).click()

    def enter_business_edit_page(self):
        self.driver.find_element(*self.first_business_edit_locator).click()











